import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

class Httputil extends StatefulWidget {
  const Httputil({super.key});

  @override
  State<Httputil> createState() => _HttputilState();
}

class _HttputilState extends State<Httputil> {
  var resultShow = '';
  get _goGetBtn => ElevatedButton(onPressed: _doGet, child: const Text('HTTP_GET'));

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Network')),
      body: Column(
        children: [
          _goGetBtn,
          Text("HTTP Get Response:$resultShow")
        ],
      ),
    );
  }

  void _doGet() async {
    var uri = Uri.parse('https://api.devio.org/uapi/test/test?requestPrams=ChatGPT');
    var response = await http.get(uri);
    if (response.statusCode == 200) {
      setState(() {
        resultShow = response.body;
      });
    }
    else {
      setState(() {
        resultShow = 'HTTP Get request FAILED, code: ${response.statusCode}, body: ${response.body}';
      });
    }
  }
}
